//
//  MainMenuViewController.m
//  Rich
//
//  Created by Kenny Chen on 13/7/30.
//  Copyright (c) 2013年 Kenny Chen. All rights reserved.
//

#import "RichCore.h"
#import "MainMenuViewController.h"
#import "AccountViewController.h"
#import "CategoryViewController.h"
#import "ExpendViewController.h"
#import "IncomeViewController.h"
#import "TransferViewController.h"
#import "QueryViewController.h"
#import "CreditCardViewController.h"

@interface MainMenuViewController ()

@end

@implementation MainMenuViewController

@synthesize navigator;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)pushAccountViewController
{
    AccountViewController *accountController;
    accountController = [[AccountViewController alloc] initWithStyle:UITableViewStylePlain];
    accountController.navigator = navigator;
    [navigator pushViewController:accountController animated:YES];
    [accountController release];
}

- (void)pushCategoryViewController
{
    CategoryViewController *categoryController;
    categoryController = [[CategoryViewController alloc] initWithStyle:UITableViewStylePlain];
    categoryController.navigator = navigator;
    [navigator pushViewController:categoryController animated:YES];
    [categoryController release];
}

- (void)pushExpendViewController
{
    ExpendViewController *expendController;
    expendController = [[ExpendViewController alloc] initWithStyle:UITableViewStylePlain];
    expendController.navigator = navigator;
    [navigator pushViewController:expendController animated:YES];
    [expendController release];
}

- (void)pushIncomeViewController
{
    IncomeViewController *incomeController;
    incomeController = [[IncomeViewController alloc] initWithStyle:UITableViewStylePlain];
    incomeController.navigator = navigator;
    [navigator pushViewController:incomeController animated:YES];
    [incomeController release];
}

- (void)pushTransferViewController
{
    TransferViewController *transferController;
    transferController = [[TransferViewController alloc] initWithStyle:UITableViewStylePlain];
    transferController.navigator = navigator;
    [navigator pushViewController:transferController animated:YES];
    [transferController release];
}

- (void)pushQueryViewController
{
    QueryViewController *queryController;
    queryController = [[QueryViewController alloc] initWithStyle:UITableViewStylePlain];
    queryController.navigator = navigator;
    [navigator pushViewController:queryController animated:YES];
    [queryController release];
}

- (void)pushSummaryViewController
{
    AccountViewController *accountController;
    accountController = [[AccountViewController alloc] initWithStyle:UITableViewStylePlain];
    accountController.mode = RichTableModeListReadonly;
    accountController.navigator = navigator;
    [navigator pushViewController:accountController animated:YES];
    [accountController release];
}

- (void)pushCreditCardViewController
{
    CreditCardViewController *creditCardController;
    creditCardController = [[CreditCardViewController alloc] initWithStyle:UITableViewStylePlain];
    creditCardController.navigator = navigator;
    [navigator pushViewController:creditCardController animated:YES];
    [creditCardController release];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 8;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Configure the cell...
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    switch ([indexPath row]) {
        case 0:
            cell.textLabel.text = RichLocaleString(@"Account Setting");
            break;
            
        case 1:
            cell.textLabel.text = RichLocaleString(@"Category Setting");
            break;
        
        case 2:
            cell.textLabel.text = RichLocaleString(@"Expend");
            break;
        
        case 3:
            cell.textLabel.text = RichLocaleString(@"Income");
            break;
        
        case 4:
            cell.textLabel.text = RichLocaleString(@"Transfer");
            break;
        
        case 5:
            cell.textLabel.text = RichLocaleString(@"Query");
            break;
        
        case 6:
            cell.textLabel.text = RichLocaleString(@"Account Summary");
            break;
        
        case 7:
            cell.textLabel.text = RichLocaleString(@"Credit Card Management");
            break;
    }
    
    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
     */
    
    switch ([indexPath row]) {
        case 0:
            [self pushAccountViewController];
            break;
            
        case 1:
            [self pushCategoryViewController];
            break;
        
        case 2:
            [self pushExpendViewController];
            break;
        
        case 3:
            [self pushIncomeViewController];
            break;
        
        case 4:
            [self pushTransferViewController];
            break;
        
        case 5:
            [self pushQueryViewController];
            break;
        
        case 6:
            [self pushSummaryViewController];
            break;
        
        case 7:
            [self pushCreditCardViewController];
            break;
    }
}

@end
